﻿/*
 *  PassBag is multi-platform software that securely manage/store passwords
 *  Copyright (C) <2009>  <Hugo Rodrigues PEREIRA>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *	
 *  You can find a copy of the GPLv3 at project <root directory>/gpl.txt
 *
 */

using System;
using System.Text;

namespace PassBag.Utils {
    /// <summary>
    /// Randomizer helpèer class
    /// </summary>
    public sealed class Randomizer {

        /// <summary>
        /// Gets the random date time.
        /// </summary>
        /// <returns>The random date time.</returns>
        public static DateTime GetRandomDateTime () {
            DateTime start = new DateTime (1995, 1, 1);
            Random gen = new Random ();
            int range = ((TimeSpan)(DateTime.Today - start)).Days;

            return start.AddDays (gen.Next (range));
        }

        /// <summary>
        /// Gets the random number.
        /// </summary>
        /// <param name="min">The min.</param>
        /// <param name="max">The max.</param>
        /// <returns>The random number.</returns>
        public static int GetRandomNumber (int min, int max) {
            Random random = new Random ();
            return random.Next (min, max);
        }

        /// <summary>
        /// Gets the random string.
        /// </summary>
        /// <param name="size">The size.</param>
        /// <param name="lowerCase">if set to <c>true</c> [lower case].</param>
        /// <returns>The random string.</returns>
        public static string GetRandomString (int size, bool lowerCase) {
            StringBuilder builder = new StringBuilder ();
            Random random = new Random ();
            char ch;
            for (int i = 0; i < size; i++) {
                ch = Convert.ToChar (Convert.ToInt32 (Math.Floor (26 * random.NextDouble () + 65)));
                builder.Append (ch);
            }
            if (lowerCase)
                return builder.ToString ().ToLower ();
            return builder.ToString ();
        }
    }
}
